home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Practical Algorithms for Image Analysis
/
Practical Algorithms for Image Analysis.iso
/
LIBIP
/
ACM_IO.C
next >
Wrap
C/C++ Source or Header
|
1999-09-11
|
7KB
|
300 lines
/*
* acm_io.c
*
* Practical Algorithms for Image Analysis
*
* Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
*/
/*
* ACM_IO
*
* routines to handle input files of type .acm
*
*/
#include <stdio.h>
#include "ip.h"
/*
* acm_prm_size()
* DESCRIPTION:
* read first entry in data file to determine number of mode parameters
* ARGUMENTS:
* file: pointer to open FILE
* RETURN VALUE:
* number of mode parameters
*/
int
acm_prm_size (file)
FILE *file;
{
int n_mode_parms;
int retval;
if (((retval = fscanf (file, "%d ", &n_mode_parms)) == 0) || (retval == EOF)) {
printf ("wrong input file format!\n");
exit (1);
}
return (n_mode_parms);
}
/*
* acm_cont_parms()
* DESCRIPTION:
* read first entry in data file to determine number of parameters
* ARGUMENTS:
* file: pointer to open FILE
* RETURN VALUE:
* number of parameters
*/
int
acm_cont_parms (file)
FILE *file;
{
int n_parms;
int retval;
if (((retval = fscanf (file, "%d ", &n_parms)) == 0) || (retval == EOF)) {
printf ("wrong input file format!\n");
exit (1);
}
return (n_parms);
}
/*
* acm_record_size()
* DESCRIPTION:
* read entry in data file to determine number of records
* ARGUMENTS:
* file: pointer to open FILE
* RETURN VALUE:
* number of records
*/
int
acm_record_size (file)
FILE *file;
{
long ln_pts;
int retval;
if (((retval = fscanf (file, "%ld ", &ln_pts)) == 0) || (retval == EOF)) {
printf ("wrong input file format!\n");
exit (1);
}
return ((int) ln_pts);
}
/*
* acm_cont_parms()
* DESCRIPTION:
* read entry in data file to determine no moments and related parms
* ARGUMENTS:
* file: pointer to open FILE
* RETURN VALUE:
* number of moments
*/
int
acm_moments (file)
FILE *file;
{
int n_moments;
int retval;
if (((retval = fscanf (file, "%d ", &n_moments)) == 0) || (retval == EOF)) {
printf ("wrong input file format!\n");
exit (1);
}
return (n_moments);
}
/*
* acm_shape_parms()
* DESCRIPTION:
* read entry in data file to determine shape parms
* ARGUMENTS:
* file: pointer to open FILE
* c_len: curvature length (float *)
* area: area (float *)
* pc_len: contour length (float *)
* p2a: global shape parameter (float *)
* e_bend: bend energy (float *)
* RETURN VALUE:
* none
*/
void
acm_shape_parms (file, c_len, area, pc_len, p2a, e_bend)
FILE *file;
float *c_len, *area, *pc_len, *p2a, *e_bend;
{
int retval;
if ((retval = fscanf (file, "%f %f %f %f %f",
c_len, area, pc_len, p2a, e_bend) == 0) || (retval == EOF)) {
printf ("wrong input file format!\n");
exit (1);
}
}
/*
* get_acm_data()
* DESCRIPTION:
* read data from file of type .acm (generated by bdym.c)
* ARGUMENTS:
* file: pointer to open FILE
* n_mode_parms: number of mode parms (int)
* mode_parms: mode parms array (int *)
* n_moments: number of moments (int)
* moments: moments array (float *)
* n_pts: number of points for power_spec and corr_fct (int)
* power_spec: power spectrum array (float *)
* corr_fct: correlation function array (float *)
* RETURN VALUE:
* none
*/
void
get_acm_data (file, n_mode_parms, mode_parms, n_moments, moments,
n_pts, power_spec, corr_fct)
FILE *file;
int n_mode_parms, n_moments, n_pts;
int *mode_parms;
float *moments;
float *power_spec, *corr_fct;
{
int i;
int retval;
for (i = 0; i < n_mode_parms; i++) {
if (((retval = fscanf (file, "%d", (mode_parms + i))) == 0) || (retval == EOF)) {
printf ("wrong input file format for data!\n");
exit (1);
}
}
for (i = 0; i < n_moments; i++) {
if (((retval = fscanf (file, "%f", (moments + i))) == 0) || (retval == EOF)) {
printf ("wrong input file format for data!\n");
exit (1);
}
}
for (i = 0; i < n_pts; i++) {
if (((retval = fscanf (file, "%f %f", (power_spec + i), (corr_fct + i))) == 0) || (retval == EOF)) {
printf ("wrong input file format for data!\n");
exit (1);
}
}
}
/*
* write_acm_file()
* DESCRIPTION:
* write power spectrum and autocorrelation function and parameters
* to file of type .acm
* ARGUMENTS:
* file: pointer to open FILE
* nv2: number of points for power_spec and corr_fct (long)
* p_spec: power spectrum array (float *)
* acf: correlation function array (float *)
* moments: moments array (float *)
* n_mom: number of moments (int)
* mode_parms: mode parms array (int *)
* n_mp: number of mode parms (int)
* c_len: curvature length (double)
* pix_ct: area (double)
* res_c_len: contour length (double)
* g_shape: global shape parameter (double)
* e_bend: bend energy (double)
* RETURN VALUE:
* none
*/
void
write_acm_file (file, nv2, p_spec, acf, moments, n_mom, mode_parms, n_mp,
c_len, pix_ct, res_c_len, g_shape, e_bend)
FILE *file;
long nv2;
float *p_spec, *acf, *moments;
double c_len, pix_ct, res_c_len, g_shape, e_bend;
int *mode_parms;
int n_mom, n_mp;
{
int i;
fprintf (file, "%d %d\n", n_mp, (int) nv2);
/*
* shape parameters
*/
fprintf (file, "%f %f %f %f %f\n",
(float) c_len, (float) pix_ct, (float) res_c_len,
(float) g_shape, (float) e_bend);
fprintf (file, "%d \n", n_mom);
for (i = 0; i < n_mp; i++)
fprintf (file, "%d\n", *(mode_parms + i));
for (i = 0; i < n_mom; i++)
fprintf (file, "%f\n", *(moments + i));
for (i = 0; i < nv2; i++)
fprintf (file, "%f %f\n", *(p_spec + i), *(acf + i));
fprintf (file, "\n");
}
/*
* write ZAHN-ROSKIES Fourier descriptors to file
*/
/*
* write_fd_file()
* DESCRIPTION:
* write ZAHN-ROSKIES Fourier descriptors to file
* ARGUMENTS:
* file: pointer to open FILE
* n_order: order of Fourier descriptors (int)
* a_n: Fourier descriptors coefficients (float *)
* length: length (double)
* area: area (double)
* ratio: ratio (double)
* RETURN VALUE:
* none
*/
void
write_fd_file (file, n_order, a_n, length, area, ratio)
FILE *file;
int n_order;
float *a_n;
double length, area, ratio;
{
int i;
fprintf (file, "%d\n", n_order);
for (i = 0; i < n_order; i++)
fprintf (file, "%f\n", *(a_n + i));
fprintf (file, "%lf\n%lf\n%lf\n", length, area, ratio);
fprintf (file, "\n");
}